<?php
namespace app\api;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/9 0009
 * Time: 下午 4:28
 */

use think\Controller;
use think\Config; 

class Base extends Controller
{ 


    public function __construct()
    {
         parent::__construct();
         $this->time = time();
		 
		 header('Access-Control-Allow-Origin:*');
        // 响应类型  
        header('Access-Control-Allow-Methods:*');
        // 响应头设置  
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
    }
  
    
    /**
     * 组装base64数组字符串
     * @param type $data
     * @param type $hasKey
     * @return type
     */
    protected function setWebBase64Code($data, $hasKey = False)
    {
        $array = array();
        $postFix = Config::get('app.base_back_postfix');
        if ($hasKey) {
            foreach ($data as $dk => $dv) {
                $array[] = $dk . '[#$%]' . $dv;
            }
            return base64_encode(implode('-', $array)) . $postFix;
        } else {
            return base64_encode(implode('-', $data)) . $postFix;
        }
    }

    /**
     * 取得base64数据
     * @param string $string
     * @return type
     */
    protected function getWebBase64Code($string,$hasKey = False)
    {
        $data = array();
        if ($hasKey) {
            $start = strlen($string) - strlen(Config::get('app.base_back_postfix'));
            $string = substr_replace($string, '', $start, strlen(Config::get('app.base_back_postfix')));
            $string = explode('-', base64_decode($string));
            foreach ($string as $vs) {
                $vs = explode('[#$%]', $vs);
                $data[$vs[0]] = $vs[1];
            }
            return $data;
        } else {
            return explode('-', base64_decode($userdata));
        }
    }
	
	
	public function _initialize(){


		# 记录当前控制器
		$module = request()->module();
		$controller = request()->controller();
		$action = request()->action();
		$assign_record = [
		'module' => $module,
		'controller' => $controller,
		'action' => $action,
		];
		if(isset($_GET['aa'])){
			//var_dump(unserialize('a:3:{i:31;a:2:{s:6:"answer";s:1:"A";s:2:"id";s:2:"31";}i:30;a:2:{s:6:"answer";s:1:"B";s:2:"id";s:2:"30";}i:29;a:2:{s:6:"answer";s:1:"A";s:2:"id";s:2:"29";}}'));
			//phpinfo();
			exit;
			$redis = new \Redis();
			 //连接
			 $redis->connect('192.168.3.201', 6379);
			 //$redis->expire('key',10);//设置失效时间[true | false]
			 //检测是否连接成功
			 $redis->select(2); //选择redis 2号库
			 echo "Server is running: " . $redis->ping();
			 $redis->close();
			
			exit;
		}
		
    }

}
